﻿//获取用户列表
function GetUserList(queryData) {
    $('#userdlg').dialog('open').dialog('setTitle', '选择部门主管');
    $('#userlist').datagrid({
        title: '用户列表',
        idField: 'UserID',
        fitColumns: 'true',
        singleSelect: true,
        autoRowHeight: true,
        nowrap: true,
        striped: true,
        pagination: true,
        url: 'User/GetList',
        queryParams: queryData,    //参数为了多条件查询预留
        columns: [[
			{ field: 'ck', checkbox: true },
			{ field: 'UserID', title: 'ID', hidden: true },
			{ field: 'UserName', title: '账号', width: 180 },
			{ field: 'EmployeeName', title: '姓名', width: 180 },
			{ field: 'DepartmentID', title: '部门', width: 180 },
			{ field: 'RoleID', title: '角色（职务）', width: 180 },
			{ field: 'Telephone', title: '固定电话', width: 180 }
        ]],
    });
}

//选择部门主管
function SelectUser() {
    var rows = $("#userlist").datagrid("getSelections");
    if (rows.length == 1) {
        var userID = rows[0].UserID;
        var employeeName = rows[0].EmployeeName;
        $("#txt_UserID").val(userID);
        $("#txt_UserName").val(employeeName);
        $('#userdlg').dialog('close');
    }
    else {
        $.messager.alert("友情提示", "请选择部门主管");
    }
}

//根据部门ID，用户名查询用户
function Search() {
    var depatmentID = $('#comb_Search_DepartmentParentID').combotree('getValue');
    var username = $('#userName').val();

    if (depatmentID == '请选择部门') {
        depatmentID = '';
    }
    if (username == '用户名称') {
        username = '';
    }
    var querData = {
        j_depatmentID: depatmentID,
        j_username: username
    };

    GetUserList(querData);
}